---
--- Created by admin.
--- DateTime: 2017/10/4 17:09
---



GuanQia = {}

GuanQia.Ui = function()
    x, y = findMultiColorInRegionFuzzy(0x921f09, "-49|3|0x901500,8|18|0x52433c,-94|4|0x5c4e43,-121|14|0x2d1e1b,-333|16|0x2d1e1b,-360|55|0xefc705,-356|48|0xfae702,-350|61|0xf6b200,-330|54|0xfef000,-336|63|0x100000,-344|47|0x060000,-360|67|0x0a0505,-367|94|0xfee100,-353|98|0xfec500,-341|100|0xfeb700,-327|99|0xfebe00,-322|94|0x4a0000,-149|51|0x030d10", 95, 259, 9, 718, 226, 0, 0)
    if x > -1 then
        shouzhi.click(x, y)
        logger.info("关卡界面")
        return true
    end
end


GuanQia.UiClose = function()
    x, y = findMultiColorInRegionFuzzy(0x921f09, "-49|3|0x901500,8|18|0x52433c,-94|4|0x5c4e43,-121|14|0x2d1e1b,-333|16|0x2d1e1b,-360|55|0xefc705,-356|48|0xfae702,-350|61|0xf6b200,-330|54|0xfef000,-336|63|0x100000,-344|47|0x060000,-360|67|0x0a0505,-367|94|0xfee100,-353|98|0xfec500,-341|100|0xfeb700,-327|99|0xfebe00,-322|94|0x4a0000,-149|51|0x030d10", 95, 259, 9, 718, 226, 0, 0)
    if x > -1 then
        shouzhi.click(x, y)
        logger.info("关卡界面关闭")
        return true
    end
end


GuanQia.findGQ = function()

    x, y = findMultiColorInRegionFuzzy(0x090401, "-1|3|0x121010,-14|-1|0xfea523,-7|4|0xfe9212,7|3|0xfe9717,37|-34|0xfef780,37|-39|0xfef787,-37|-32|0xccc764,-1|-73|0xfef7a5,-5|-73|0xfef7a5,0|5|0x0f0b0c,-4|-1|0x1e1b18,-37|-39|0xccc76d", 85, 2, 183, 717, 1084, 0, 0)

    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0x0c0602, "-5|-5|0x130a04,-16|1|0xfeaa28,7|4|0xfe9f1e,36|-32|0xfef780,-39|-30|0xfef780,-38|-39|0xfef78c,-39|-30|0xfef780,-11|-69|0xfef7a5,-2|-70|0xfef7a5,4|-70|0xfef7a5", 85, 14, 202, 708, 1070, 0, 0)
    end
    if x==-1 then
        x, y = findMultiColorInRegionFuzzy(0x0d0c0e,"-8|-2|0xfe9c1b,8|0|0xfe9414,-20|-19|0xfee806,-7|-18|0xfee01d,6|-22|0xf6eb49,26|-24|0xfdf000,19|-12|0xfe9510,14|-21|0x5b0000,-2|-13|0xfe9c02,-21|-14|0xfea900,17|-16|0x5a0000", 85, 7, 197, 711, 537, 0, 0)
    end

    if x==-1 then
        x, y = findMultiColorInRegionFuzzy(0x283643,"-6|-1|0xfe9717,9|-1|0xfe9717,-20|-18|0xfedb08,0|-15|0xfeb507,6|-16|0x580000,15|-20|0x5d0000,22|-12|0xfe8b00,39|-42|0xfef785,-35|-41|0xfef784,-35|-36|0xfef77c,39|-45|0xfef789", 85, 23, 191, 718, 1086, 0, 0)

    end
    if x > -1 then
        shouzhi.click(x, y)
        logger.info("查找关卡")
        return true
    end
end


GuanQia.juQing=function()

    x, y = findMultiColorInRegionFuzzy(0x010203,"249|-6|0x060607,419|-10|0x73ddf7,419|-24|0x73ddf7,514|-24|0x73ddf7,514|-11|0x73ddf7,186|-1129|0x978d01,186|-1072|0x995c00", 95, 9, 46, 713, 1262, 0, 0)
    if x==-1 then
        x, y = findMultiColorInRegionFuzzy(0x010203,"-158|-1|0x000203,-284|-57|0x030404,-398|-95|0x040504,-294|-136|0x020304,-204|-135|0x050404,-112|-130|0x000203,-73|-1081|0x998400,-79|-1107|0x050202,130|-1125|0x02080a,-80|-1122|0x927b03,-78|-1129|0x968c02,-80|-1134|0x948c03,-71|-1115|0x956b00,-80|-1107|0x060203,-62|-1076|0x996f00,-48|-1078|0x997700,-51|-1068|0x994a00", 95, 3, 58, 718, 1246, 0, 0)
    end
    if x > -1 then
        shouzhi.click(x, y)
        return true
    end
end

GuanQia.zhanDou = function()

    x, y = findMultiColorInRegionFuzzy(0x552112, "-83|-14|0x0e0b0b,15|-67|0x201715,-34|20|0xfef322,-19|-26|0xfde80e,20|-33|0xfef407,28|-28|0xfef03b,37|-27|0xfde701,31|30|0xfad200,-20|24|0xfdeb19,1|25|0x5f2012,-6|-9|0x5f2012,-26|-17|0x2a1008,-22|36|0x2a1008", 95, 179, 523, 531, 807, 0, 0)
    if x==-1 then
        x, y = findMultiColorInRegionFuzzy(0xfde60a,"-13|3|0xfbde10,28|5|0xfbd61f,21|7|0x2a1008,28|5|0xfbd61f,45|-2|0xfef13e,-52|20|0x140c0b,-25|89|0x1e1614,-63|20|0x0f0c0c,47|54|0xfad405,-1|50|0xfce000", 95, 184, 503, 529, 819, 0, 0)
    end

    -- boss开战
    if x==-1 then
        x, y = findMultiColorInRegionFuzzy(0xfceb40,"16|-8|0xfef111,11|-21|0xfef114,1|4|0xfbde00,45|-6|0xfef000,38|17|0xf8c201,51|13|0xf9ca00,70|7|0xfbdf1c,79|21|0xf7ba00,90|-1|0x960000,26|11|0x9b0000,88|3|0x9f0000,5|18|0x860000", 95, 221, 532, 510, 667, 0, 0)
    end
    if  x==-1 then
        x, y = findMultiColorInRegionFuzzy(0x2c333d,"-7|0|0xfe9313,-8|-2|0xfe9c1b,7|1|0xfe9010,19|-12|0xfe9109,16|-17|0x5b0001,13|-25|0xfef54b,5|-16|0x580000,7|-12|0xfe9005,-3|-13|0xfe9b04,-4|-18|0x580000,-13|-16|0xfdcd33,-22|-12|0xfe8e00,-20|-19|0xfee600", 95, 7, 175, 709, 618, 0, 0)
    end
    if x > -1 then
        shouzhi.click(x, y)
        logger.info("开始战斗")
        return true
    end
end

GuanQia.bossZhanDou=function()

    x, y = findMultiColorInRegionFuzzy(0xfefe09,"-29|8|0x2b0d00,-58|46|0xf2dd0c,-30|38|0xf6d305,14|25|0xdb2800,31|55|0xf0dd0e,110|21|0xfefa0c,97|-10|0x24160f,109|-24|0xfdc601,98|-26|0xfcad01,109|19|0xfefa0c,109|54|0xf3e107,120|50|0x2b0d00", 95, 172, 347, 549, 601, 0, 0)
    if x > -1 then
        shouzhi.click(x, y)
        logger.info("boss战斗")
        return true
    end
end

GuanQia.zhanSheng = function()
    x, y = findMultiColorInRegionFuzzy(0xf48f04, "-72|38|0xef8404,-79|61|0xecea07,-47|30|0xfd8f02,-7|56|0xf6ec05,-3|67|0xf7f33a,-135|42|0xe58906,-144|8|0xfcfb91,-202|56|0xf5ee12,-157|46|0x2b0c00,-121|33|0x020000,-113|27|0x2b0c00,-159|49|0x2b0c00,-64|72|0x2b0c00,16|46|0x2b0c00", 95, 173, 378, 594, 761, 0, 0)
    if x > -1 then
        shouzhi.click(x, y)
        logger.info("战胜")
        return true
    end
end

GuanQia.tongGuanJiangLi=function()

    x, y = findMultiColorInRegionFuzzy(0xf66600,"98|-4|0xf33c00,77|2|0xfefe06,20|40|0xeed204,7|30|0xe19b05,78|35|0xf9ab01,65|57|0xf2ed05,77|56|0x270b00,128|62|0xfcfc77,127|71|0x260a00,168|43|0xeed204,158|60|0xf9f123,171|61|0x290c00,213|41|0xfcda04,245|38|0xeecf04,276|29|0xe08903,273|16|0x280c00,243|26|0x080100,153|35|0x130802", 95, 136, 344, 617, 609, 0, 0)
    if x > -1 then
        shouzhi.click(x, y)
        logger.info("通关奖励")
        return true
    end
end

GuanQia.bossShiBai=function()

    x, y = findMultiColorInRegionFuzzy(0x1d1c17,"-6|28|0x1c1c16,-32|106|0x1a1a16,27|105|0x1b1b15,-14|186|0x13130f,70|187|0x13130f,-136|144|0x7a7771,-87|69|0x8a887c,93|69|0x89877b,49|31|0x8e877d,-21|283|0x92846a,-6|284|0xc8c9c5,87|283|0xc0bdb5,99|282|0x9b8e75,4|310|0x9fa0aa,76|309|0x9fa1ab", 95, 197, 682, 522, 1031, 0, 0)
    if x > -1 then
        logger.info("打不过boss了")
        return true
    end
end
GuanQia.bossUiClose=function()

    x, y = findMultiColorInRegionFuzzy(0xf03f1d,"12|-7|0xf36d15,-8|14|0xfcfcfc,-53|18|0xfcfcfc,-64|-2|0x310a00,-60|3|0xfee384,-77|-10|0x310a00,-61|-26|0xfefcf3,-42|-12|0xfeefba,-37|-4|0x310a00,-64|-2|0x310a00,27|4|0xfcfcfc", 95, 270, 19, 717, 98, 0, 0)
    if x > -1 then
        shouzhi.click(x, y)
        logger.info("boss界面关闭")
        return true
    end
end




-- 前往经营
GuanQia.qianWangJingYing = function( yes)
    x, y = findMultiColorInRegionFuzzy(0xc8ab89, "138|-3|0xccb08e,123|36|0xa17956,20|34|0xa17956,3|-211|0xfce835,19|-211|0xfce835,14|-185|0xfe9806,51|-196|0xfeb217,100|-199|0xfdbf1f,101|-193|0xfeac14,139|-205|0xfdd72a,134|-206|0xfdde41,139|-191|0xfea510,93|-189|0xfea10d,15|78|0x0c0807,130|76|0x0b0707", 95, 123, 892, 546, 1210, 0, 0)

    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xc66f2f,"64|0|0xc86e2f,-67|25|0x534031,138|18|0x47372a,-39|39|0x7d4516,110|39|0x814816,-24|88|0x0b0706,-35|-185|0xfe9805,94|98|0x0d0808,65|-186|0xfe9805,66|-199|0xfdbf1f,16|-196|0xfeb217,66|-212|0xfcec3c,104|-205|0xfdd72a", 90, 214, 884, 540, 1250, 0, 0)

    end
    if x > -1 then
        if yes then
            shouzhi.click(x, y)
        end
        logger.info("打不过了")
        return true
    end
end

GuanQia.ZhanBai = function()
    x, y = findMultiColorInRegionFuzzy(0xfcfb91, "9|31|0xe97107,26|57|0xf7f32f,-32|40|0xf5e206,-61|45|0xf6ea0f,-13|37|0x2b0c00,-1|56|0x2b0c00,84|4|0x2b0c00,78|60|0x2b0c00,67|55|0xebe705,67|55|0xebe705,141|-5|0xf48f04,137|44|0xf5e206,139|60|0xf7f33a,80|62|0x2b0c00,28|18|0x2b0c00,-43|1|0xfa7204,75|10|0xfca502", 95, 176, 407, 570, 789, 0, 0)
    if x > -1 then
        shouzhi.click(x, y)
        logger.info("战胜")
        return true
    end
end

GuanQia.xiaYiGuan=function()
    x, y = findMultiColorInRegionFuzzy(0x000000,"260|3|0x000000,-24|662|0x000000,240|662|0x000000,322|49|0x515ba3,-53|49|0x515ba3,-53|64|0x515ba3,322|64|0x515ba3,322|56|0x000001,-52|56|0x000000,110|75|0x425f82,149|36|0x466588", 95, 108, 173, 660, 894, 0, 0)
    if x > -1 then
        shouzhi.click(x, y)
        logger.info("下一关")
        return true
    end
end


GuanQia.zhuaBuChengGong=function()
    x, y = findMultiColorInRegionFuzzy(0xfeca00,"9|-11|0xfedc00,13|12|0xa50000,20|17|0xfeab00,55|13|0xfeb200,57|-8|0xfed900,81|-8|0xfed900,77|8|0xfebc00,-19|13|0xfeb200,-67|18|0x880000,-74|-1|0xfecb00,-129|17|0xfeab00,-111|-21|0xfeeb00,-101|25|0xfe9c00,-76|10|0xfeb700", 95, 150, 166, 549, 352, 0, 0)
    if x > -1 then
        shouzhi.click(x, y)
        logger.info("抓捕成功")
        return true
    end
end
GuanQia.run = function()
    -- todo 进入关卡
    -- 查找关卡
    --keepScreen(true);
    GuanQia.findGQ()
    GuanQia.zhanDou()

    GuanQia.zhanSheng()
    GuanQia.tongGuanJiangLi()
    GuanQia.xiaYiGuan()
    GuanQia.juQing()
    GuanQia.bossZhanDou()
    GuanQia.zhuaBuChengGong()
    --keepScreen(false);
    mSleep(300)
    -- 开始游戏
    -- 关卡失败
    if GuanQia.bossShiBai() then
        -- 退出脚本
        lua_exit()
        GuanQia.bossUiClose()
    end

    -- 战败
    if  GuanQia.qianWangJingYing(true) then
        FuZhai.onlyZiChanRun()
    end
    
    
end